package br.com.linkers.controller;

import java.io.Serializable;
import java.util.List;

import javax.faces.bean.ManagedBean;
import javax.faces.bean.ManagedProperty;
import javax.faces.bean.SessionScoped;

import br.com.linkers.dao.EmailsDAO;
import br.com.linkers.entity.Emails;

@SessionScoped
@ManagedBean(name="emailBean")
public class EmailBean implements Serializable {

	private static final long serialVersionUID = -5079696674426996294L;

	@ManagedProperty("#{usuarioBean}")
	private UsuarioBean usuarioBean;

	EmailsDAO dao = new EmailsDAO();
	
	List<Emails> emailsUL;
	List<Emails> emailsView;
	
	
	
	public void atualizaEmailUL(){
		//ERROR usando o LAZY
		//failed to lazily initialize a collection
		//return usuarioBean.getUsuarioLogado().getList_telefone();
		Long id = (long) this.usuarioBean.getUsuarioLogado().getId();
		this.emailsUL = (List<Emails>) dao.buscaPorIdUsuario(id);
	}
	
	public void atualizaEmailView(){
		Long id = (long) this.usuarioBean.getUsuarioView().getId();
		this.emailsView = (List<Emails>) dao.buscaPorIdUsuario(id);
	}
	
	
	
	

	public UsuarioBean getUsuarioBean() {
		return usuarioBean;
	}

	public void setUsuarioBean(UsuarioBean usuarioBean) {
		this.usuarioBean = usuarioBean;
	}

	public List<Emails> getEmailsUL() {
		atualizaEmailUL();
		return emailsUL;
	}

	public void setEmailsUL(List<Emails> emailsUL) {
		this.emailsUL = emailsUL;
	}


	public List<Emails> getEmailsView() {
		atualizaEmailView();
		return emailsView;
	}

	public void setEmailsView(List<Emails> emailsView) {
		this.emailsView = emailsView;
	}
	
	
	

}
